/**
 * Created by user on 2018/11/12.
 */

import React from 'react'
import { getAuthority } from './authority'
const checkAuth = (authority) => {
  const { role, browser, token } = getAuthority()
  if (window.navigator.userAgent.toLowerCase() !== browser) {
    return false
  }
  if (!token) {
    return false
  }
  if (authority.indexOf(role) < 0) {
    return false
  }
  return true
}

export default class Authorized extends React.Component {
  render() {
    const { children, noMatch, authority } = this.props
    return checkAuth(authority) ? children : noMatch
  }
}
